<template>
  <div class="app-container">
    <!--    {{ searchObj }}-->
    <!-- banner列表 -->
    <template>
      <el-table :data="searchObj" style="width: 100%"><!--v-loading="loading"-->
        <el-table-column prop="id" label="记录id" width="180"></el-table-column>
        <el-table-column prop="cid" label="商品id" width="180"></el-table-column>
        <el-table-column prop="uid" label="用户id" width="180"></el-table-column>
        <el-table-column prop="number" label="兑换数量"></el-table-column>
        <el-table-column prop="otime" label="兑换时间"></el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="danger" icon="el-icon-delete" size="small" @click="handleClick(scope.$index, scope.row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
          :current-page="current"
          :page-size="limit"
          :total="total"
          style="padding: 30px 0; text-align: center;"
          layout="total, prev, pager, next, jumper"
          @current-change="getList"
      />
    </template>

  </div>
</template>
<script>
//引入api接口
import hospitalSetApi from "@/api/integral";

export default {
  // 定义数据模型
  data() {
    return {
      current: 1,
      limit: 2,
      searchObj: [],
      total: 0,
      page: {
        pageNo: 1,
        pageSize: 2
      },
      scope: null,
      delVisible: false,//删除提示弹框的状态
      msg: null//记录每一条的信息，便于取id
    }
  },
  // 页面渲染成功后获取数据
  created() {
    this.getList();
  },
  methods: {//定义方法对api接口的方法调用
    //医院设置列表
    getList(page = 1) {
      this.page.pageNo = page
      hospitalSetApi.showList(this.page)
          .then(res => {
            this.total = res.data.total
            this.searchObj = res.data.records
            this.limit = res.data.size
            console.log(res)
          })//请求成功
          .catch(error => {
            console.log(error)
          })//请求失败
    },
    //单行删除
    handleClick(index, row) {
      this.msg = row
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        hospitalSetApi.delete(this.msg.id).then(res => {
          console.log(this.msg.id)
          if (res.data == true) {
            this.$message({
              type: 'success',
              message: '删除成功!',
            });
          } else {
            this.$message({
              type: 'defeated',
              message: '删除失败!',
            });
          }
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
};
</script>
